import { ClassesDto } from './../common/classes.dto';
import { StudentsService } from './students.service';
import {
  Body,
  Controller,
  Get,
  ParseIntPipe,
  Post,
  Query,
} from '@nestjs/common';

@Controller('students')
export class StudentsController {
  constructor(private readonly studentsService: StudentsService) {}

  //根据学生id查询姓名
  @Get('getNameById')
  getNameById(@Query('id', ParseIntPipe) id: number) {
    return this.studentsService.getSutdentName(id);
  }

  //向学生表中新增一条记录
  @Get('setStudent')
  setStudent(@Query() data: any) {
    return this.studentsService.setStudent(data.id, data.name);
  }

  //根据Id获取课程
  @Get('getClass')
  getClassById(@Query('id', ParseIntPipe) id: number) {
    return this.studentsService.findClass(id);
  }

  @Post('setClass')
  setClass(@Body() classes: ClassesDto) {
    return this.studentsService.setClass(classes.students, classes.className);
  }
}
